package com.rtx.wms.std.so.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rtx.api.annotation.DataSourceAnnotation;
import com.rtx.wms.std.so.bean.ApiOrderdetailfinish;
import com.rtx.wms.std.so.bean.ApiOrdersfinish;
import com.rtx.wms.std.so.bean.Pickdetail;
import com.rtx.wms.std.so.mapper.ApiOrderdetailfinishMapper;
import com.rtx.wms.std.so.mapper.ApiOrdersfinishMapper;
import com.rtx.wms.std.so.mapper.PickdetailMapper;
import com.rtx.wms.std.so.service.ApiOrdersfinishService;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wq
 * @since 2023-04-18
 */
@Service
public class ApiOrdersfinishServiceImpl extends ServiceImpl<ApiOrdersfinishMapper, ApiOrdersfinish> implements ApiOrdersfinishService {

    @Autowired
    private ApiOrderdetailfinishMapper apiOrderdetailfinishMapper;
    
    @Autowired
    PickdetailMapper pickdetailMapper;

    @DataSourceAnnotation
    @Override
    public List<ApiOrdersfinish> selectApiOrdersfinishByWrapper(String whseid, LambdaQueryWrapper<ApiOrdersfinish> queryWrapper) {
        List<ApiOrdersfinish> ordersList = baseMapper.selectList(queryWrapper);
        for(ApiOrdersfinish o : ordersList){
            LambdaQueryWrapper<ApiOrderdetailfinish> query = Wrappers.lambdaQuery();
            query.eq(ApiOrderdetailfinish::getBatchid,o.getBatchid());
            o.setDetails(apiOrderdetailfinishMapper.selectList(query));
        }
        return ordersList;
    }

    @DataSourceAnnotation
    @Override
    public void updateByWrapper(String whseid, LambdaUpdateWrapper<ApiOrdersfinish> wrapper) {
        baseMapper.update(null,wrapper);
    }

    @DataSourceAnnotation
    @Override
    public void addApiOrdersfinish(String whseid, ApiOrdersfinish o) {
    	for(ApiOrderdetailfinish od : o.getDetails()){
    		apiOrderdetailfinishMapper.insert(od);
    	}
        baseMapper.insert(o);
    }

    @DataSourceAnnotation
	@Override
	public List<ApiOrdersfinish> selectApiOrdersByWrapperNoDetail(String whseid, LambdaQueryWrapper<ApiOrdersfinish> queryWrapper) {
		return baseMapper.selectList(queryWrapper);
	}
    
    
}
